import React, {useMemo, useState} from 'react';

function App(props) {
    const [newsList,setNewsList] = useState([
        {
            id:1,
            newsTitle:"新闻一"
        },{
            id:2,
            newsTitle: "新闻二"
        }
    ]);
    const [num,setNum] = useState(0)
    const newsListMap = useMemo(function(){
        console.log(1)
        return newsList.map(item=>{
            return (
                <p key={item.id}>{item.newsTitle}</p>
            )
        })
    },[newsList,num])
    return (
        <div>
            <button onClick={()=>setNum(num+1)}>{num}</button>
            <button onClick={()=>{
                let id = newsList.length+1;
                setNewsList([
                    ...newsList,
                    {
                        id,
                        newsTitle: "新闻"+id
                    }
                ])
            }}>获取</button>
            {
                newsListMap
            }
        </div>
    );
}

export default App;